home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12343 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: alisa.org!wjjr
  3. From: wjjr@alisa.org (John J. Rushford)
  4. Subject: Re: routine for yesterday's date
  5. X-Newsreader: TIN [version 1.2 PL2]
  6. Organization: My place on the Front Range.
  7. Message-ID: <Dp3B56.FKI@alisa.org>
  8. References: <315c4d0f.19874776@ottnews.shl.com> <1996Mar30.043002.19054@sq.com>
  9. Date: Sat, 30 Mar 1996 16:58:18 GMT
  10.  
  11. Mark Brader (msb@sq.com) wrote:
  12. : Bruce Coghill (75323.455@compuserve.com) writes at 2:48 PM, March 29, 1996:
  13. :  
  14. : > In my C manual the time.h and time functions are described
  15. : > and how I can pull off each element in the structure (like year,
  16. : > month, day, day-of-the-year), but it isn't clear to me how to subtract
  17. : > a day.
  18.  
  19. : This is question 13.14 on the FAQ list, but I'd like to expand a bit
  20. : on what it says there.
  21.  
  22. : Bruce, you have gotten as far as calling time() and localtime().  The
  23. : next thing is to use the normalizing feature of mktime().  Suppose that
  24. : you have a variable of type struct tm called x, and you've just put the
  25. : current time into it using localtime().  Now you basically just want to
  26. : do something like this:
  27.  
  28. :     x.tm_day--;          /* back 1 day */
  29. :     (void) mktime (&x);    /* normalize */
  30.  
  31. [stuff deleted]
  32.  
  33. Why bother with mktime() when it is so much easier to use the following and
  34. you don't have to bother with errors gotten from x.tm_day--;
  35.  
  36.     long ticks
  37.     struct tm * dt;
  38.  
  39.     time(&ticks);
  40.  
  41.     /* 86400 seconds in a day */
  42.     ticks -= 86400
  43.  
  44.     dt = localtime (&ticks);
  45.  
  46. regards
  47. -- 
  48. John J. Rushford              
  49. Westminster, Colorado___/\_/\_
  50. wjjr@alisa.org (alisa.org is powered by FreeBSD)
  51.  
  52.